package tobsn.locationcalendar.service;

import tobsn.locationcalendar.R;
import tobsn.locationcalendar.map.TobsnMapActivity;
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class NotificationService extends IntentService {

	private static final int NOTIFICATION_ID = 1;
	private NotificationManager mManager;

	public NotificationService() {
		super("TobsnLocationService");
	}

	@Override
	protected void onHandleIntent(Intent intent) {

		mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

		CharSequence barTitle = intent.getCharSequenceExtra("barTitle");
		CharSequence contentTitle = intent.getCharSequenceExtra("contentTitle");
		CharSequence contentText = intent.getCharSequenceExtra("contentText");

		Notification notification = new Notification(R.drawable.grungegreen,
				barTitle, System.currentTimeMillis());

		long[] vibrate = { 0, 300, 300, 200, 500 };
		notification.vibrate = vibrate;
		notification.defaults |= Notification.DEFAULT_SOUND;
		notification.flags |= Notification.FLAG_AUTO_CANCEL;

		Context context = getApplicationContext();
		Intent notificationIntent = new Intent(this, TobsnMapActivity.class);
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
				notificationIntent, 0);

		notification.setLatestEventInfo(context, contentTitle, contentText,
				contentIntent);

		mManager.notify(NOTIFICATION_ID, notification);

	}

}
